package view.other
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import manager.LevelManange;
	import manager.SoundManage;
	
	public class LockView extends Sprite
	{
		
		private var sprite:Sprite;
		
		private var callback:Function;
		
		private var lockAry:Array=[];
		
		private var mc:MovieClip;
		public function LockView(call:Function)
		{
			callback = call;
			super();
			initface();
			this.addEventListener(MouseEvent.CLICK,onClick);
			this.addEventListener(MouseEvent.MOUSE_OVER,mouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT,mouseOut);
			this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
		}
		
		public function unlockNext():void{
			for(var i:int=0;i<lockAry.length;i++){
				if(int(lockAry[i].name) == LevelManange.getInstance().curLevel){
					mc['txt'+i+1].text = i+1+'';
				}
			}
		}
		
		private function mouseDown(e:MouseEvent):void{
			if(e.target!=mc){
				e.target.alpha = 0;
			}
		}
		
		private function mouseOver(e:MouseEvent):void{
			if(e.target!=mc){
				e.target.alpha = 1;
			}
		}
		
		private function mouseOut(e:MouseEvent):void{
			if(e.target!=mc){
				e.target.alpha = 0;
			}
		}
		
		protected function onClick(event:MouseEvent):void
		{
			if(event.target!=mc){
				LevelManange.getInstance().curLevel = lockAry.indexOf(event.target)+1;
				SoundManage.getInstance().playBtnClick();
				callback();
			}
		}
		
		private function initface():void
		{
			mc = new Lock();
			this.addChild(mc);
			for(var i:int=1;i<=20;i++){
				mc['btn'+i].alpha = 0;
				mc['btn'+i].buttonMode = true;
				mc['txt'+i].mouseEnabled=false;
				if(LevelManange.getInstance().userLevel<i){
					mc['txt'+i].text = '?';
					mc['btn'+i].mouseEnabled = false;
					mc['btn'+i].mouseChildren = false;
				}
				lockAry.push(mc['btn'+i]);
			}
			
		}
	}
}